#ifndef __PROTOCOL_H
#define __PROTOCOL_H

#include "global.h"
#include "Power.h"


extern add_t Devic_Add;


#define OPEN_ALL_LED							0x18
#define CLOSE_ALL_LED							0x17


#define GET_FAULT_LED_ADDRESS						0x30
#define GET_EPS_WORK_POSITION  					0X32
#define SET_LED_WORK_MODULE							0x40
#define SET_EPS_WORK_MODULE 						0x50
#define RADIO_SET_EPS_WORK_MODULE 			0x60
#define ADD_LED_ADDRESS									0xF1
#define ADD_LED_ADDRESS_AFFIRM					0xF3
#define DELE_LED_ADDRESS								0xF5
#define DELE_LED_ADDRESS_AFFIRM					0xF7
#define DELE_ALL_LED_ADDRESS						0xF9
#define DELE_ALL_LED_ADDRESS_AFFIRM			0xFB
#define GET_ALL_LED_ADDRESS							0xE1

#define SET_EPS_ADDRESS									0xC7
#define RESPONSE_EPS_ADDRESS					0xC8
#define SET_MODEL_ADDRESS								0xC9 
#define RESPONSE_MODEL_ADDRESS					0xCA




#define RESPONSE_GET_FAULT_LED_ADDRESS			0x31
#define RESPONSE_GET_EPS_WORK_POSITION 			0X33
#define RESPONSE_SET_LED_WORK_MODULE				0x41
#define RESPONSE_SET_EPS_WORK_MODULE 				0x51
#define RESPONSE_ADD_LED_ADDRESS						0xF2
#define RESPONSE_ADD_LED_ADDRESS_AFFIRM			0xF4
#define RESPONSE_DELE_LED_ADDRESS						0xF6
#define RESPONSE_DELE_LED_ADDRESS_AFFIRM		0xF8
#define RESPONSE_DELE_ALL_LED_ADDRESS				0xFA
#define RESPONSE_DELE_ALL_LED_ADDRESS_AFFIRM 0xFC
#define RESPONSE_GET_ALL_LED_ADDRESS					0xE2

#define  ntohl(x)   (((x>>24) & 0xFF)|((x>>8) & 0xFF00)|\
                        ((x & 0xFF00)<<8) | ((x & 0xFF)<<24)\
                     )

#define Setbit(x,y) x |= (1<<y) 

#define Clrbit(x,y) x &= ~(1<<y)

#define Getbit(x,y)	(x & (1<<y))>>y

typedef int8(*SigleInsHander)(uint8 uch_op, void *pdata, uint8 uch_length, uint8 *data_area, uint16 sn,uint8 *uch_back_type);

typedef struct
{
  uint8 funcCode;
  SigleInsHander h;
}InsHander;

typedef int8(*RepInsHander)(uint8 *data_area,uint8 *uch_back_type);

typedef struct
{
	uint8 funcCode;
	uint8 len;
	uint8 index;
	RepInsHander Report;
}RepHander;

typedef union 
{                                          
  uint32 TargetData;
  uint8  InitData[4];
}UnionData;


typedef struct
{
	uint32 addr;
	uint8  info;
	
}Res_Dev;

uint16 MakeBackFrame(uint8 uin_type,uint8 uch_len,uint8* out);

uint16 ProtocolAnalysis(uint8 *in,uint8 *out);

void LampsProtocolAnalysis(uint8 *in,uint8 *out);

void Lamp_Information_Process(uint8 *data_area);

void Commd_lamp(uint8 com,uint8* out,uint8 uch_len);

void Read_send(uint8 commd);

void All_LED_Close(void);

void All_Led_Open(void);

#endif  //__PROTOCOL_H
